package java_collection.hashmap;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import static java.lang.System.out;

public class HashMapDemo {
	public static void main(String[] args) {
		
		Map <Integer,String> map = new HashMap <Integer,String>();
		map.put(1, "One");
		map.put(2, "Two");
		map.put(3, "Three");
		map.put(4, "Four");
		map.put(9, "Nine");
		map.put(5, "Five");
		
		out.println(map);
		
		out.printf("Value of key (2) is %s\n",map.get(2));
		
		// Map is not iterable,
		// however we can get set-collection
		Set <Integer> keys = map.keySet();
		
		out.println("Printing length of each value");
		String s;
		for(Integer i: keys){
			s = map.get(i);
			out.printf("%s(%d) ",s,s.length());
		}
		
		out.println("\n");
		
		out.println("Removing key = 3");
		map.remove(3);
		out.println(map);
		
		out.println("\n");
		
		out.println("Adding key = 0");
		map.put(0, "0");
		out.println(map);
		
		out.println("\n");
		
		out.println("Changing value for key = 0");
		map.put(0,"Zero");
		out.println(map);
		
		out.println("\n");
		
		out.println("Does HashMap contains 4 as key: " 
										+ map.containsKey(4));
		
		out.println("Does HashMap contains Four as value: " 
									+ map.containsValue("Four"));
		
		out.println("Does HashMap contains 14 as key: " 
										+ map.containsKey(14));
		
		out.println("\n");
		
		out.println("Is HashMap empty: " +  map.isEmpty());
		out.println("Size of Map: " + map.size());
		
		out.println("Clearing Hashmap...");
		map.clear();
		
		out.println("Size of Map: " + map.size());
		
		out.println("Is HashMap empty: " +  map.isEmpty());
		
	}
}
